package com.example.shopping_mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shopping_mall.R;
import com.example.shopping_mall.bean.UiRecommendBean;

import java.util.List;

//人气推荐列表
public class RecommendAdapter extends RecyclerView.Adapter<RecommendAdapter.MyHolder>{

    private Context context;
    private List<UiRecommendBean> recommendBeanList;

    public RecommendAdapter(Context context) {
        this.context = context;
    }

    public void setRecommendBeanList(List<UiRecommendBean> recommendBeanList) {
        this.recommendBeanList = recommendBeanList;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.recommend_list_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.recommendimage.setImageBitmap(recommendBeanList.get(position).getRecommendimage());
        holder.recommendname.setText(recommendBeanList.get(position).getRecommendname());
        holder.recommenddetail.setText(recommendBeanList.get(position).getRecommenddetail());
        holder.recommendprice.setText(String.valueOf(recommendBeanList.get(position).getRecommendprice()));
    }

    @Override
    public int getItemCount() {
        return null==recommendBeanList?0:recommendBeanList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder{

        ImageView recommendimage;
        TextView recommendname;
        TextView recommenddetail;
        TextView recommendprice;

        public MyHolder(@NonNull View itemView) {
            super(itemView);

            recommendimage=itemView.findViewById(R.id.recommend_item_image);
            recommendname=itemView.findViewById(R.id.recommend_item_commodity);
            recommenddetail=itemView.findViewById(R.id.recommend_item_commodity_detail);
            recommendprice=itemView.findViewById(R.id.recommend_item_price);
        }
    }
}
